
<?php
$script = "jQuery('#cb_createTasks').click(function(){
 	$('#oldTask').hide();
	$('#newTask').show();
});
jQuery('#cb_addToTasks').click(function(){
	$('#newTask').hide();
 	$('#oldTask').show();
});	
jQuery('#cb_allowTasks').click(function(){
	$('#oldTask').hide();
 	$('#newTask').hide();	
});
";

Yii::app()->clientScript->registerScript("cb",$script,CClientScript::POS_READY);
?>
<div class="srbacForm">
  <?php echo SHtml::form() ?>
  <div class="action">
    <?php echo "<b>".$controller."</b>" ?>
  </div>
      
  <?php if (count($actions)>0) { ?>
	<div>
		<?php /* echo  SHtml::checkBoxList("actions", "", $actions,array("checkAll"=>"<b>".Yii::t('adm','Check All')."</b>",));*/ ?>
		<ul>
			<li class="w_230 o_h f_l"><?php echo Yii::t('adm','操作')?></li>
			<li class="w_120 o_h f_l"><?php echo Yii::t('adm','操作名')?></li>
			<li class="w_120 o_h f_l"><?php echo Yii::t('adm','权限集')?></li>
			<?php foreach($actions as $value){?>
				<li class="w_230 o_h f_l"><?php echo CHtml::checkBox('action['.$value.']',false)?> <?php echo $value?></li>
				<li class="w_120 o_h f_l"><input type="input" size="13" name="actionName[<?php echo $value?>]" value="<?php echo MemGroup::model()->getActionName($value)?>"/></li>
				<li class="w_120 o_h f_l">
					<?php 
					$tasksName = MemGroup::model()->getTasksName($value);
					if(!empty($tasksName)){
						echo $tasksName;
		                echo CHtml::ajaxLink(
							CHtml::image('/images/delete.png',"删除权限"),
							array('deleteAllow','action'=>$value,'controller'=>$controller,'tasks'=>$tasksName),
							array(
								'type'=>'POST',
								'update'=>'#controllerActions',
								'beforeSend' => 'function(){
										$("#controllerActions").addClass("srbacLoading");
									}',
								'complete' => 'function(){
										$("#controllerActions").removeClass("srbacLoading");
									}',
							)
						);
					}else{
						echo " ";
					}
                	?>
				</li>
			<?php }?>
		</ul>
	</div>
  <?php } ?>



  <div class="simple">
    <hr>
    <?php echo Yii::t('adm',"distribute authority").":" ?><br>

      <?php echo CHtml::radioButton("createTasks", true, array("id"=>"cb_createTasks",'class'=>'ml_40','value'=>'1')); ?>
      <?php echo Yii::t('adm','addNewPrivilage') ?>
      <?php echo CHtml::radioButton("createTasks", false, array("id"=>"cb_addToTasks",'class'=>'mr_10','value'=>'2'));?>
      <?php echo Yii::t('adm','addToPrivilage') ?>
      <?php echo CHtml::radioButton("createTasks", false, array("id"=>"cb_allowTasks",'class'=>'mr_10','value'=>'3')); ?>
      <?php echo Yii::t('adm','addallow'); ?>
  </div>
  <div id="newTask">
	  <div class="simple ml_40">
	  		<?php echo Yii::t('adm','权限名称'); ?>:&nbsp;&nbsp;
	      <?php echo SHtml::textField("tasks[user]",'',array('size'=>'30')); ?>
	  </div>
	  <div class="simple ml_40">
	  		<?php echo Yii::t('adm','权限标识'); ?>:&nbsp;&nbsp;
		  <?php echo SHtml::textField("tasks[admin]",MemGroup::model()->createTaskName($controller),array('size'=>'30',"readonly"=>false)); ?>
	  </div>
  </div>
  <div id="oldTask" class="d_n ml_40">
  		<?php echo Yii::t('adm','选择权限'); ?>:&nbsp;&nbsp;
  		<?php echo CHtml::dropDownList('tasks[old][]','',MemGroup::model()->getPrivilege(),array('class'=>'mr20','size'=>"8",'multiple'=>'true')); ?>
  		<span class="c_999"><?php echo Yii::t('adm','Hold the ALT key to choose more'); ?></span>
  </div>
  <div class="simple">
    <?php echo SHtml::hiddenField("controller", $controller)?>
  </div>
  <div class="action">
    <?php echo CHtml::ajaxButton(Yii::t('adm','Save'),
    array("createPrivilege"),
    array(
    'type'=>'POST',
    'update'=>'#controllerActions',
    'beforeSend' => 'function(){
                      $("#controllerActions").addClass("srbacLoading");
                  }',
    'complete' => 'function(){
                      $("#controllerActions").removeClass("srbacLoading");
                  }',
    ));?>
  </div>
  <?php echo SHtml::endForm()?>
</div>

